const state = {
	list:[
		{
			name:'胡继源大帅哥',
			phone:'18824227957',
			city:'广东省-东莞市-万江区',
			address:'坝新路爱迪花园北区27栋2座502室',
			isDefault:true
		},
		{
			name:'小帅哥',
			phone:'12345678910',
			city:'北京市-海淀区',
			address:'幸福花园',
			isDefault:false
		}
	]
};
const mutations = {
	createPath(state,obj){
		state.list.push(obj)
	},
	modifyPath(state,{index,item}){
		for (let key in item) {
			state.list[index][key] = item[key];
		}
	},
	// 清除已有默认地址标识
	clearDefaultPaht(state){
		state.list.forEach(v=>{
			if (v.isDefault) {
				v.isDefault = false
			}
		})
	}
};
const actions = {
	createPathFn({commit},obj){
		if (obj.isDefault) {
			commit('clearDefaultPaht')
		};
		commit('createPath',obj)
	},
	modifyPathFn({commit},obj){
		if (obj.item.isDefault) {
			commit('clearDefaultPaht')
		};
		commit('modifyPath',obj)
	}
};
const getters = {
	defaultPath(state){
		return state.list.filter(v=> v.isDefault);
		
	}
};
export default {
	state,mutations,actions,getters
}
